// JavaScript Document
(function($){
 jQuery.fn.timeref = function(){
		return this.each(function(){
			var date = timerefer(this.title);
			if ( date )
				jQuery(this).text( date );
		});
	};
	
	
var weekdays = new Array(7);
weekdays[0] = "Minggu";
weekdays[1] = "Senin";
weekdays[2] = "Selasa";
weekdays[3] = "Rabu";
weekdays[4] = "Kamis";
weekdays[5] = "Jum'at";
weekdays[6] = "Sabtu";

var month=new Array(12);
month[0]="Januari";
month[1]="Februari";
month[2]="Maret";
month[3]="April";
month[4]="Mei";
month[5]="Juni";
month[6]="Juli";
month[7]="Agustus";
month[8]="September";
month[9]="Oktober";
month[10]="November";
month[11]="Desember";

function timerefer(time){
	var date = new Date((time || "").replace(/-/g,"/").replace(/[TZ]/g," ")),
diff = (((new Date()).getTime() - date.getTime()) / 1000),
day_diff = Math.floor(diff / 86400);
var data=time.split(' ');
//var tim = data[1];
var dtt = data[0];

weekday_value = date.getDay();
month_value = date.getMonth();
date_value = date.getDate();
/*var ver=date.split(' ');
var vor = ver[0];
*/
var hours = date.getHours();
   var am = true;
   if (hours > 12) {
      am = false;
      hours -= 12;
   } else if (hours == 12) {
      am = false;
   } else if (hours == 0) {
      hours = 12;
   }

   var minutes = date.getMinutes();
   var tim = pad2(hours) + ":" + pad2(minutes) +" "+(am ? "AM" : "PM");

//console.log(day_diff);
if ( isNaN(day_diff) || day_diff < 0 )
return;
return day_diff == 0 && (
diff < 60 && Math.floor(diff)+" detik yang lalu" ||
diff < 120 && "1 menit yang lalu" ||
diff < 3600 && Math.floor( diff / 60 ) + " menit yang lalu" ||
diff < 7200 && "1 jam yang lalu" ||
diff < 86400 && Math.floor( diff / 3600 ) + " jam yang lalu") ||
day_diff == 1 && "Kemarin jam" + " "+ tim   ||
day_diff < 7 && weekdays[weekday_value] +" jam "+ tim  ||
day_diff < 31 && month[month_value]+" "+date_value+" jam "+ tim  ||
day_diff > 31 && month[month_value]+" "+date_value+" jam "+ tim;
}
	
function pad2(number) {
     return (number < 10 ? '0' : '') + number ;
}	
	
})(jQuery);
